package co.com.services.persona;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.PersonaDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartPersonaService")
public class PersonaServices {

	@GET
	@Path("/getAllPersona")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getPersona() throws NamingException {
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().consultarAllPersona())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@POST
	@Path("/getPersonaId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getPersonaId(PersonaDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().consultarPersonaId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getPersonaCd")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getPersonaCd(PersonaDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().consultarPersonaCd(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setPersona")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setPersona( PersonaDTO json){ 
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().insertarPersona(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editPersona")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditPersona(PersonaDTO json){ 
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().editPersona(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removePersona")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemovePersona(PersonaDTO json){ 
		return Response.ok(DelegateContextEJB.getPersonaBeanLocal().removePersona(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}



}
